package com.boruishangge.common.activity

import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import com.alibaba.android.arouter.facade.annotation.Route
import com.boruishangge.common.APlusARoute
import com.boruishangge.common.APlushConstant
import com.boruishangge.common.R
import com.boruishangge.common.databinding.ActivitySettingViewBinding
import com.boruishangge.persagysdk.base.BaseActivity
import com.boruishangge.persagysdk.uitls.StringUtils

@Route(path = APlusARoute.aplus_setting_Router)
class SettingActivity :BaseActivity(),View.OnClickListener{

    lateinit var binding: ActivitySettingViewBinding
    val that = this@SettingActivity

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_setting_view)
        binding.ivBack.setOnClickListener(that)
        whiteStatusBar()
        binding.bvSave.setOnClickListener(that)
        binding.bvClear.setOnClickListener(that)
        binding.evHttpurl.setText(APlushConstant.getWebUrl())
    }
    override fun onClick(v: View?) {
         when(v){
             binding.ivBack->{
                 finish()
             }

             binding.bvClear->{
                 APlushConstant.clearListAccount()
                 Toast.makeText(that,"清除成功",Toast.LENGTH_LONG).show()
             }
             binding.bvSave->{
               var text=  binding.evHttpurl.text.toString()
                 if (StringUtils.checkNull(text)){
                     Toast.makeText(that,"地址不能为空",Toast.LENGTH_LONG).show()
                     return
                 }
                 if (!text.contains("http")){
                     Toast.makeText(that,"请输入http 请求地址",Toast.LENGTH_LONG).show()
                     return
                 }
                 Toast.makeText(that,"保存成功",Toast.LENGTH_LONG).show()
                 APlushConstant.setWebUrl(text);
                 finish()


             }
         }
    }

}